<?php


namespace app\common\validate;


class BannerValidate extends CommonValidate
{
    protected $rule    = [
        'id|ID'           => 'require|integer|between:1,100000000',
        'media_url|媒体URL' => 'require',
        'event_id|事件ID'   => 'require|integer|between:1,100000000',
        'event|事件'        => 'require|bannerEvent',
        'is_carousel|事件'  => 'require|bool',
    ];
    protected $message = [];
    protected $scene   = [
        'postBanner'   => [
            'event',
            'event_id',
            'media_url',
            'is_carousel',
        ],
        'putBanner'    => [
            'id',
            'media_url',
            'event',
            'event_id',
            'is_carousel',
        ],
        'deleteBanner' => ['id'],
    ];

    protected function bannerEvent($value): bool
    {
        try {
            if (in_array($value, [
                'category',
                'product',
                'article',
            ], true)) {
                return true;
            }
            return false;
        } catch (\Exception $e) {
            return false;
        }
    }
}